package org.ftc.service;

import java.util.Date;
import java.util.List;

import org.ftc.dao.CommitteeTeamDao;
import org.ftc.domain.CommitteeTeam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service;

@Service
public class CommitteeTeamService {
	
	@Autowired
	CommitteeTeamDao committeeTeamDao;
	@Autowired
	private UsersService usersService;
	
	public CommitteeTeam load(String id) {
		return committeeTeamDao.load(id);
	}

	public CommitteeTeam get(String id) {
		return committeeTeamDao.get(id);
	}
	
	public CommitteeTeam getChecked() {
		return committeeTeamDao.getChecked();
	}
	
	public synchronized boolean save(CommitteeTeam entity) {
		Authentication userDetails = SecurityContextHolder.getContext().getAuthentication();
		if (userDetails != null)
			entity.setCreationUser(userDetails.getName());
		entity.setCreationDate(new Date());
		return committeeTeamDao.save(entity);
	}


	public synchronized boolean saveOrUpdate(CommitteeTeam entity) {
		return committeeTeamDao.saveOrUpdate(entity);
	}

	public synchronized boolean update(CommitteeTeam entity) {
		entity.setModifyDate(new Date());
		entity.setModifyUser(SecurityContextHolder.getContext().getAuthentication().getName());
		return committeeTeamDao.update(entity);
	}

	public synchronized boolean delete(CommitteeTeam entity) {
		return committeeTeamDao.delete(entity);
	}

	public synchronized boolean delete(String id) {
		return committeeTeamDao.delete(id);
	}
	

	public List<CommitteeTeam> findAll() {
		return committeeTeamDao.findAll();
	}

	public long countAll() {
		return committeeTeamDao.countAll();
	}
	
	
	
}
